#define  _CRT_SECURE_NO_WARNINGS

#include "sort.h"

int cmp_int(const void* a, const void* b)
{
	int arg1 = *(int*)a;
	int arg2 = *(int*)b;
	return (arg1 > arg2) - (arg1 < arg2);
}

void text1()
{
	int arr[] = { 5,2,7,4,9,1,0,3,8,6 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_int);
	print_int(arr, sz);
}

int cmp_struct_name(const void* a, const void* b)
{
	return strcmp((*(struct people*)a).name, (*(struct people*)b).name);
}

void text2()
{
	struct people p[] = { { "xiaoshuai", 25, 75.5 }, { "xiaomei", 24, 54.3 }, { "xiaochou", 23, 67.8 } };
	int sz = sizeof(p) / sizeof(p[0]);
	bubble_sort(p, sz, sizeof(p[0]), cmp_struct_name);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s ", (*(p + i)).name);
	}
}

int cmp_struct_weight(const void* a, const void* b)
{
	double arg1 = (*(struct people*)a).weight;
	double arg2 = (*(struct people*)b).weight;
	return (arg1 > arg2) - (arg1 < arg2);
}

void text3()
{
	struct people p[] = { { "xiaoshuai", 25, 75.5 }, { "xiaomei", 24, 54.3 }, { "xiaochou", 23, 67.8 } };
	int sz = sizeof(p) / sizeof(p[0]);
	bubble_sort(p, sz, sizeof(p[0]), cmp_struct_weight);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%lf ", (*(p + i)).weight);
	}
}

int cmp_struct_age(const void* a, const void* b)
{
	int arg1 = (*(struct people*)a).age;
	int arg2 = (*(struct people*)b).age;
	return (arg1 > arg2) - (arg1 < arg2);
}

void text4()
{
	struct people p[] = { { "xiaoshuai", 25, 75.5 }, { "xiaomei", 24, 54.3 }, { "xiaochou", 23, 67.8 } };
	int sz = sizeof(p) / sizeof(p[0]);
	bubble_sort(p, sz, sizeof(p[0]), cmp_struct_age);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", (*(p + i)).age);
	}
}

int main()
{
	//text1();
	/*text2();*/
	text3();
	/*text4();*/
	return 0;
}


